package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.find.webview.WebViewActivity;
import com.wuhan.template.module.home.entity.ActivityInfoEntity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/10 0010.
 */
public class HuoDongListAdapter extends MyBaseAdapter<ActivityInfoEntity.ListBean>{
    private List<ActivityInfoEntity.ListBean> list;
    private Context context;
    private ImageLoader loader;
    private DisplayImageOptions options;
    public HuoDongListAdapter(Context context,  List<ActivityInfoEntity.ListBean> list) {
        super(context, list);
        this.context = context;
        this.list = list;
        loader = ((BaseApplication)(context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .cacheInMemory(true)
                .showImageOnFail(R.mipmap.app_logo)
                //.displayer(new RoundedBitmapDisplayer(15))
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.huodong_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        ViewHolder holder = new ViewHolder();

        return holder;
    }

    @Override
    public void bindViews(View view, final BaseViewHolder viewHolder) {
        String title = list.get(viewHolder.position).getTitle();
        String count = list.get(viewHolder.position).getComment_num();
        ActivityInfoEntity.ListBean.IndexpicBean indexpic = list.get(viewHolder.position).getIndexpic();
        String imageUrl = indexpic.getHost()+ indexpic.getDir()+ indexpic.getFilepath()+ indexpic.getFilename();
        ((ViewHolder) viewHolder).imageInfo.setScaleType(ImageView.ScaleType.FIT_XY);
        ((ViewHolder)viewHolder).title.setText(title);
        ((ViewHolder)viewHolder).count.setText("评论数为: "+count);
        loader.displayImage(imageUrl, ((ViewHolder) viewHolder).imageInfo, options);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("url",list.get(viewHolder.position).getContent_url());
                intent.putExtra("title",list.get(viewHolder.position).getColumn_name());
                context.startActivity(intent);
            }
        });

    }

    public static class ViewHolder extends BaseViewHolder{
        @BindView(R.id.activity_imageInfo)
        ImageView imageInfo;
        @BindView(R.id.activity_info_title)
        TextView title;
        @BindView(R.id.activity_info_count)
        TextView count;
    }
}
